from types import ModuleType
from typing import TypeVar, Type, List

T = TypeVar("T")


def load_entries(mod: ModuleType, base_cls: Type[T]) -> List[T]:
    result: list = []
    accessed = set()

    def traverse(x):
        nonlocal result, accessed

        if id(x) in accessed:
            return
        else:
            accessed.add(id(x))

        if isinstance(x, ModuleType):
            for key in dir(x):
                if not key.startswith("_"):
                    traverse(getattr(x, key))
        elif issubclass(x, base_cls):
            result.append(x())

    traverse(mod)
    return result
